package com.itouch.bracelet.diseaseinfo;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.itouch.bracelet.R;
import com.itouch.bracelet.bean.DiseaseInfoDetail;

public class DiseaseInfoDetailAdapter extends BaseAdapter {

	LayoutInflater inflater;
	ArrayList<DiseaseInfoDetail> mData;

	public DiseaseInfoDetailAdapter(Context context,
			ArrayList<DiseaseInfoDetail> data) {
		inflater = (LayoutInflater) context
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		
		if (data == null)
			mData = new ArrayList<DiseaseInfoDetail>();
		else
			mData = data;
	}
	
	public void refreshData(ArrayList<DiseaseInfoDetail> data)
	{
		if(data == null)
		{
			mData.clear();
		}
		else
		{
			mData = data;
		}
		notifyDataSetChanged();
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return mData.size();
	}

	@Override
	public Object getItem(int arg0) {
		// TODO Auto-generated method stub
		return mData.get(arg0);
	}

	@Override
	public long getItemId(int arg0) {
		// TODO Auto-generated method stub
		return arg0;
	}

	@Override
	public View getView(int arg0, View arg1, ViewGroup arg2) {
		// TODO Auto-generated method stub
		MyViewHolder viewHolder;
		if(arg1 == null)
		{
			viewHolder = new MyViewHolder();
			arg1 = inflater.inflate(R.layout.diseaseinfodetail_item, null);
			viewHolder.tv = (TextView) arg1.findViewById(R.id.title);
			arg1.setTag(viewHolder);
		}
		else
		{
			viewHolder = (MyViewHolder) arg1.getTag();
		}
		viewHolder.tv.setText(mData.get(arg0).getTitle());
		
		return arg1;
	}
	
	class MyViewHolder
	{
		TextView tv;
	}

}
